/*
 * pn_hl.h
 *
 *  Created on: 09.05.2013
 *      Author: Roma Jam
 */

#ifndef PN_HL_H_
#define PN_HL_H_


#include "pn_lld.h"

#define OK              0
#define FAILURE         1

#define NEW_CRD_SEARCH_DELAY        102
#define CRD_STILL_IN_CHECK_DELAY    450
#define CRD_TRANSACTION_TIMEOUT     65535
#define CMD_TIMEOUT                 45
#define DATA_TIMEOUT_JCOP           5450
#define DATA_TIMEOUT_MFRE           450

enum PnCardType_t{
    pnct_Type_A_106kbps = 0x01,
    pnct_Type_B_106kbps = 0x02,
    pnct_FeliCa_212kbps = 0x04,
    pnct_FeliCa_424kbps = 0x08,
    pnct_Jewel_106kbps  = 0x10
};

class Pn_t {
private:
    uint8_t PnType;
    uint32_t ITimer, CardTimer;
    uint32_t DataTimeout;
    // Hi-level
     void FieldOn()  { Pn_lvl1.Cmd(PN_CMD_RF_CONFIGURATION, 2, 0x01, 0x01); } // Cfg=0x01=RF field, value=0x01=FieldOn
     void FieldOff() { Pn_lvl1.Cmd(PN_CMD_RF_CONFIGURATION, 2, 0x01, 0x00); } // Cfg=0x01=RF field, value=0x00=FieldOff


     // Card
     bool CardIsAppeared();
     uint8_t CheckCardIsStillNear();
     uint8_t CheckJavaCardFuseState();
public:
    void Init();
    void Task();
    void CrdPwrOff();
};

extern Pn_t Pn;

#endif /* PN_HL_H_ */
